home *** CD-ROM | disk | FTP | other *** search
/ Your Choice 1 / your choice.zip / your choice / PRGMMING / VISIONIX / VDOSHU.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-23  |  50KB  |  2,773 lines

  1. {
  2. ════════════════════════════════════════════════════════════════════════════
  3.  
  4.  Visionix DOS High-Level Functions Unit (VDOSHIGH)
  5.    Version 0.5
  6.  Copyright 1991,92,93 Visionix
  7.  ALL RIGHTS RESERVED
  8.  
  9. ────────────────────────────────────────────────────────────────────────────
  10.  
  11.  Revision history in reverse chronological order:
  12.  
  13.  Initials  Date      Comment
  14.  --------  --------  -------------------------------------------------------
  15.  
  16.   jrt      10/27/93  Moved code from VDOS into here.
  17.    \
  18.     \
  19.      lpg       03/25/93  Fixed DOS_GetMediaID, DOS_SetMediaID and made sure
  20.                            they indicated the Drive Number.
  21.  
  22.      lpg       03/15/93  Added Source Documentation
  23.  
  24.      mep       02/11/93  Cleaned up code for beta release
  25.  
  26.      jrt       02/08/93  Sync with beta 0.12 release
  27.  
  28.      lpg       12/08/92  Created
  29.  
  30.  
  31.   jrt      10/13/93  Added GetDirFromPath, GetNameFromPath,
  32.                      GetExtFromPath, RemoveExtraSlash.
  33.  
  34.   mep      04/25/93  Added DeviceExist
  35.  
  36.   rag      04/22/93  Added DriveExist.
  37.  
  38.   lpg      03/25/93  Added: GetVolLabel,GetFileSysType
  39.  
  40.   lpg      03/15/93  Added Source Documentation
  41.  
  42.   jrt      03/08/93  First logged revision.  Took functions from VGEn
  43.                      and moved them here.
  44.  
  45. ════════════════════════════════════════════════════════════════════════════
  46. }
  47.  
  48. (*-
  49.  
  50. [SECTION: Section 3: Operating System Services]
  51. [CHAPTER: Chapter 1: The DOS High-level functions unit]
  52.  
  53. [TEXT]
  54.  
  55. <Overview>
  56.  
  57. The VDOSHu unit implements various DOS oriented functions.
  58.  
  59. More documentation will be added to this unit in the next BETA
  60. release.
  61.  
  62. <Interface>
  63.  
  64. -*)
  65.  
  66.  
  67. UNIT VDOSHu;
  68.  
  69.  
  70. Interface
  71.  
  72. Uses
  73.  
  74.   DOS,
  75.   VTypesu,
  76.   VGenu;
  77.  
  78. {────────────────────────────────────────────────────────────────────────────}
  79.  
  80.  
  81. {------------------}
  82. { Diskette and DOS }
  83. {------------------}
  84.  
  85. Procedure DOS_GetData(        Var Version        : WORD;
  86.                               Var OEM            : BYTE;
  87.                               Var Serial         : LONGINT   );
  88.  
  89. Function  DOS_GetVersion                                       : WORD;
  90.  
  91. Function  DOS_GetOEM                                           : BYTE;
  92.  
  93. Function  DOS_GetSerial                                        : LONGINT;
  94.  
  95. Function  DOS_GetStartupDrive                                  : BYTE;
  96.  
  97. Function  DOS_GetMSDOSVersion(Var DosInHMA       : BOOLEAN;
  98.                               Var Revision       : BYTE      ) : WORD;
  99.  
  100. Function  DOS_GetDiskSpaceFree(   Drive          : BYTE      ) : LONGINT;
  101.  
  102. Function  DOS_GetDevInputStatus(  Handle         : WORD;
  103.                               Var Status         : BYTE      ) : BYTE;
  104.  
  105. Function  DOS_GetDevOutputStatus( Handle         : WORD;
  106.                               Var Status         : BYTE      ) : BYTE;
  107.  
  108. Function  DOS_IsRemovMediaDev(    Drive          : BYTE;
  109.                               Var Remov          : BOOLEAN   ) : WORD;
  110.  
  111. Function  DOS_GetMediaID(         Drive          : BYTE;
  112.                               Var InfoLevel      : WORD;
  113.                               Var SerialNbr      : LONGINT;
  114.                               Var VolLabel       : STRING;
  115.                               Var FileSysType    : STRING    ) : WORD;
  116.  
  117. Function  DOS_SetMediaID(         Drive          : BYTE;
  118.                                   InfoLevel      : WORD;
  119.                                   SerialNbr      : LONGINT;
  120.                                   VolLabel       : STRING;
  121.                                   FileSysType    : STRING    ) : WORD;
  122.  
  123. Function  DOS_GetExtErrText(  VAR Description    : STRING;
  124.                               VAR ErrCause       : STRING;
  125.                               VAR Recommend      : STRING;
  126.                               VAR ErrSource      : STRING    ) : WORD;
  127.  
  128.  
  129.  
  130.  
  131. Function  GetDOSVersion                        : WORD;
  132.  
  133. Function  DisketteStatus(            Drive     : WORD    ) : BYTE;
  134.  
  135. Function  FloppyReady(               Drive     : WORD    ) : BOOLEAN;
  136.  
  137. Function  PutSlash(                  S         : STRING  ) : STRING;
  138.  
  139. Function  UnPutSlash(                S         : STRING  ) : STRING;
  140.  
  141. Function  PutDot(                    S         : STRING  ) : STRING;
  142.  
  143. Function  UnPutDot(                  S         : STRING  ) : STRING;
  144.  
  145. Function  FileExist(                 fn        : PathStr ) : BOOLEAN;
  146.  
  147. Function  GetFileTime(               fn        : PathStr ) : LONGINT;
  148.  
  149. Function  GetFileAttr(               fn        : PathStr ) : WORD;
  150.  
  151. Function  GetFileSize(               fn        : PathStr ) : LONGINT;
  152.  
  153. Function  DirExist(                  stDir     : DirStr  ) : BOOLEAN;
  154.  
  155. Function  DirEmpty(                  stDir     : DirStr  ) : BOOLEAN;
  156.  
  157. Function  EraseDir(                  stDir     : DirStr  ) : BOOLEAN;
  158.  
  159. Function  PredDir(                   stDir     : DirStr  ) : DirStr;
  160.  
  161. Function  InDir(                     stDir     : DirStr  ) : DirStr;
  162.  
  163. Procedure MkSubDir(                  S         : STRING  );
  164.  
  165. Function  MaskWildcards(             fn        : PathStr;
  166.                                      fnMask    : PathStr ) : PathStr;
  167.  
  168. Procedure FileCRC16(                 FName     : STRING;
  169.                                  Var Result    : WORD    );
  170.  
  171. Procedure FileCRC32(                 FName     : STRING;
  172.                                  Var Result    : LONGINT );
  173.  
  174. Function  GetVolLabel(               Drive     : BYTE    ) : STRING;
  175.  
  176. Function  GetFileSysType(            Drive     : BYTE    ) : STRING;
  177.  
  178. Function  DriveExist(                Drive     : CHAR    ) : BOOLEAN;
  179.  
  180. Function  DeviceExist(               Name      : STRING  ) : BOOLEAN;
  181.  
  182. (*
  183. Function  TextSeek(              Var F         : Text;
  184.                                      Target    : LongInt ) : Boolean;
  185. *)
  186.  
  187. Function  GetDirFromPath(            Path      : STRING  ) : STRING;
  188. Function  GetNameFromPath(           Path      : STRING  ) : STRING;
  189. Function  GetExtFromPath(            Path      : STRING  ) : STRING;
  190.  
  191. Function  RemoveExtraSlash(          Path      : STRING  ) : STRING;
  192.  
  193.  
  194. {────────────────────────────────────────────────────────────────────────────}
  195.  
  196. Implementation
  197.  
  198. {────────────────────────────────────────────────────────────────────────────}
  199.  
  200. (*-
  201.  
  202. [FUNCTION]
  203.  
  204. Procedure DOS_GetData(        Var Version        : WORD;
  205.                               Var OEM            : BYTE;
  206.                               Var Serial         : LONGINT   );
  207.  
  208. [PARAMETERS]
  209.  
  210. Version     VAR Returned Dos Version
  211. OEM         VAR Returned Dos OEM Code
  212. Serial      VAR Returned Dos Serial Number
  213.  
  214. [RETURNS]
  215.  
  216. (Function : None)
  217. (VAR : [Version] Dos Version)
  218. (VAR : [OEM] Dos OEM Code)
  219. (VAR : [Serial] Dos Serial Number)
  220.  
  221. [DESCRIPTION]
  222.  
  223. [SEE-ALSO]
  224.  
  225. [EXAMPLE]
  226.  
  227. -*)
  228.  
  229. Procedure DOS_GetData(        Var Version        : WORD;
  230.                               Var OEM            : BYTE;
  231.                               Var Serial         : LONGINT   );
  232.  
  233. {$IFNDEF OS2}
  234.  
  235. Assembler;
  236. ASM
  237.  
  238.   PUSH DS
  239.  
  240.   MOV  AH, $30
  241.   INT  $21
  242.  
  243.   LES  DI, [Version]
  244.   LDS  SI, [OEM]
  245.   MOV  word PTR ES:DI, AX         { Version }
  246.   MOV  byte PTR DS:SI, BH         { OEM Code }
  247.  
  248.   LES  SI, [Serial]
  249.   XOR  BH, BH
  250.   MOV  word PTR ES:DI, BX         { High Order Word of Serial }
  251.   MOV  word PTR ES:DI+4, CX       { Low Order Word of serial  }
  252.  
  253.   POP  DS
  254.  
  255. END;  { DOS_GetData }
  256.  
  257. {$ELSE}
  258.  
  259. BEGIN
  260.  
  261.   Version := 200;
  262.   OEM     := 99;
  263.   Serial  := 1010101;
  264.  
  265.   {!^!}
  266.  
  267. END;
  268.  
  269. {$ENDIF}
  270.  
  271. {────────────────────────────────────────────────────────────────────────────}
  272.  
  273. (*-
  274.  
  275. [FUNCTION]
  276.  
  277. Function DOS_GetVersion                                        : WORD;
  278.  
  279. [PARAMETERS]
  280.  
  281. (None)
  282.  
  283. [RETURNS]
  284.  
  285. Dos Version
  286.  
  287. [DESCRIPTION]
  288.  
  289. [SEE-ALSO]
  290.  
  291. [EXAMPLE]
  292.  
  293. -*)
  294.  
  295. Function DOS_GetVersion                                        : WORD;
  296.  
  297. Var
  298.  
  299.   Version : WORD;
  300.   OEM     : BYTE;
  301.   Serial  : LONGINT;
  302.  
  303. BEGIN
  304.  
  305.   DOS_GetData( Version, OEM, Serial );
  306.   DOS_GetVersion := Version;
  307.  
  308. END;  { DOS_GetVresion }
  309.  
  310. {────────────────────────────────────────────────────────────────────────────}
  311.  
  312. (*-
  313.  
  314. [FUNCTION]
  315.  
  316. Function DOS_GetOEM                                            : BYTE;
  317.  
  318. [PARAMETERS]
  319.  
  320. (None)
  321.  
  322. [RETURNS]
  323.  
  324. Dos OEM Code
  325.  
  326. [DESCRIPTION]
  327.  
  328. [SEE-ALSO]
  329.  
  330. [EXAMPLE]
  331.  
  332. -*)
  333.  
  334. Function DOS_GetOEM                                            : BYTE;
  335.  
  336. Var
  337.  
  338.   Version : WORD;
  339.   OEM     : BYTE;
  340.   Serial  : LONGINT;
  341.  
  342. BEGIN
  343.  
  344.   DOS_GetData( Version, OEM, Serial );
  345.   DOS_GetOEM := OEM;
  346.  
  347. END;  { DOS_GetOEM }
  348.  
  349. {────────────────────────────────────────────────────────────────────────────}
  350.  
  351. (*-
  352.  
  353. [FUNCTION]
  354.  
  355. Function DOS_GetSerial                                         : LONGINT;
  356.  
  357. [PARAMETERS]
  358.  
  359. (None)
  360.  
  361. [RETURNS]
  362.  
  363. Dos Serial Number
  364.  
  365. [DESCRIPTION]
  366.  
  367. [SEE-ALSO]
  368.  
  369. [EXAMPLE]
  370.  
  371. -*)
  372.  
  373. Function DOS_GetSerial                                         : LONGINT;
  374.  
  375. Var
  376.  
  377.   Version : WORD;
  378.   OEM     : BYTE;
  379.   Serial  : LONGINT;
  380.  
  381. BEGIN
  382.  
  383.   DOS_GetData( Version, OEM, Serial );
  384.   DOS_GetSerial := Serial;
  385.  
  386. END;  { DOS_GetSerial }
  387.  
  388. {────────────────────────────────────────────────────────────────────────────}
  389.  
  390. (*-
  391.  
  392. [FUNCTION]
  393.  
  394. Function DOS_GetStartupDrive                                   : BYTE;
  395.  
  396. [PARAMETERS]
  397.  
  398. (None)
  399.  
  400. [RETURNS]
  401.  
  402. Start up Drive Number (1=A,2=B,...)
  403.  
  404. [DESCRIPTION]
  405.  
  406. [SEE-ALSO]
  407.  
  408. [EXAMPLE]
  409.  
  410. -*)
  411.  
  412. Function DOS_GetStartupDrive                                   : BYTE;
  413.  
  414. {$IFNDEF OS2}
  415.  
  416. Assembler;
  417. ASM
  418.  
  419.   MOV  AH, $33
  420.   MOV  AL, $05
  421.   INT  $21
  422.  
  423.   MOV  AL, DL
  424.  
  425. END;  { DOS_GetStartupDrive }
  426.  
  427. {$ELSE}
  428.  
  429. BEGIN
  430.  
  431.   DOS_GetStartupDrive := 2;
  432.  
  433. END;
  434.  
  435. {$ENDIF}
  436.  
  437. {────────────────────────────────────────────────────────────────────────────}
  438.  
  439. (*-
  440.  
  441. [FUNCTION]
  442.  
  443. Function DOS_GetMSDOSVersion( Var DosInHMA       : BOOLEAN;
  444.                               Var Revision       : BYTE      ) : WORD;
  445.  
  446. [PARAMETERS]
  447.  
  448. DosInHMA    VAR Returned Is DOS Loaded in High Memory?
  449. Revision    VAR Returned DOS Revision
  450.  
  451. [RETURNS]
  452.  
  453. (Function : Operation Error Code) (0=Success)
  454. (VAR      : [DosInHMA] Is DOS Loaded in High Memory?)
  455. (VAR      : [Revision] DOS Revision)
  456.  
  457. [DESCRIPTION]
  458.  
  459. [SEE-ALSO]
  460.  
  461. [EXAMPLE]
  462.  
  463. -*)
  464.  
  465. Function DOS_GetMSDOSVersion( Var DosInHMA       : BOOLEAN;
  466.                               Var Revision       : BYTE      ) : WORD;
  467.  
  468. {$IFNDEF OS2}
  469.  
  470. Assembler;
  471. ASM
  472.  
  473.  
  474.   MOV  AH, $33
  475.   MOV  AL, $06
  476.   INT  $21
  477.  
  478.   PUSH DS
  479.   PUSH ES
  480.  
  481.   LES  DI, [DosInHMA]
  482.   LDS  SI, [Revision]
  483.  
  484.   AND  DL, $07
  485.   MOV  byte PTR DS:SI, DL
  486.  
  487.   CMP  DH, $10
  488.   JNE  @@1
  489.  
  490.   MOV  byte PTR ES:DI, $01   { DosInHMA = TRUE }
  491.   JMP  @@2
  492.  
  493.  @@1:
  494.   MOV  byte PTR ES:DI, $00   { DosInHMA = FALSE }
  495.  
  496.  @@2:
  497.  
  498.   POP  ES
  499.   POP  DS
  500.  
  501. END;  { DOS_GetMSDOSVersion }
  502.  
  503. {$ELSE}
  504.  
  505. BEGIN
  506.  
  507. END;
  508.  
  509. {$ENDIF}
  510.  
  511. {────────────────────────────────────────────────────────────────────────────}
  512.  
  513. (*-
  514.  
  515. [FUNCTION]
  516.  
  517. Function DOS_GetDiskSpaceFree(    Drive          : BYTE      ) : LONGINT;
  518.  
  519. [PARAMETERS]
  520.  
  521. Drive       Drive Number (+80h for HD)
  522.  
  523. [RETURNS]
  524.  
  525. Free Space on Selected Drive
  526.  
  527. [DESCRIPTION]
  528.  
  529. [SEE-ALSO]
  530.  
  531. [EXAMPLE]
  532.  
  533. -*)
  534.  
  535. Function DOS_GetDiskSpaceFree(    Drive          : BYTE      ) : LONGINT;
  536.  
  537. {$IFNDEF OS2}
  538.  
  539. Var
  540.  
  541.   SPC,BPS,
  542.   AvailClust,
  543.   ClustPDrv  : WORD;
  544.  
  545. BEGIN
  546.  
  547.   ASM
  548.  
  549.     MOV  DL, Drive
  550.     MOV  AH, $36
  551.     INT  $21
  552.  
  553.     MOV  SPC, AX
  554.     MOV  AvailClust, BX
  555.     MOV  BPS, CX
  556.     MOV  ClustPDrv, DX
  557.  
  558.   END;
  559.  
  560.   DOS_GetDiskSpaceFree := LONGINT( SPC ) * LONGINT( AvailClust ) *
  561.                           LONGINT( BPS ) * LONGINT( ClustPDrv );
  562.  
  563. END;  { DOS_GetDiskSpaceFree }
  564.  
  565. {$ELSE}
  566.  
  567. BEGIN
  568.  
  569. END;
  570.  
  571. {$ENDIF}
  572.  
  573.  
  574. {────────────────────────────────────────────────────────────────────────────}
  575.  
  576. (*-
  577.  
  578. [FUNCTION]
  579.  
  580. Function DOS_GetDevInputStatus( Handle    : WORD;
  581.                             Var Status    : BYTE      ) : BYTE;
  582.  
  583. [PARAMETERS]
  584.  
  585. Handle      Device or File Handle
  586. Status      VAR Returned Device or File Input Status Code
  587.  
  588. [RETURNS]
  589.  
  590. (Function : Operation Error Code) (0=Success)
  591. (VAR      : [Status] Device or File Input Status Code)
  592.  
  593. [DESCRIPTION]
  594.  
  595. Status returns as follows:
  596.  
  597.   Devices:  $00 = Not Ready,      $FF = Ready
  598.   Files  :  $00 = Pointer at EOF, $FF = Ready
  599.  
  600. [SEE-ALSO]
  601.  
  602. [EXAMPLE]
  603.  
  604. -*)
  605.  
  606. Function DOS_GetDevInputStatus( Handle    : WORD;
  607.                             Var Status    : BYTE      ) : BYTE;
  608.  
  609.  
  610. {$IFNDEF OS2}
  611.  
  612. Assembler;
  613. ASM
  614.  
  615.   MOV  BX, Handle
  616.   MOV  AH, $44
  617.   MOV  AL, $06
  618.   INT  $21
  619.  
  620.   LES  DI, [Status]
  621.  
  622.   JNC  @@1
  623.  
  624.   MOV  AL, AH                { Code = Error }
  625.   MOV  byte PTR ES:DI, $00
  626.   JMP  @@2
  627.  
  628.  @@1:
  629.   MOV  byte PTR ES:DI, AL    { Status = Result }
  630.   XOR  AL, AL                { Code = No Error }
  631.  
  632.  @@2:
  633.  
  634. END;  { DOS_GetDevInputStatus }
  635.  
  636. {$ELSE}
  637.  
  638. BEGIN
  639.  
  640.   {!^!}
  641.  
  642. END;
  643.  
  644. {$ENDIF}
  645.  
  646. {────────────────────────────────────────────────────────────────────────────}
  647.  
  648. (*-
  649.  
  650. [FUNCTION]
  651.  
  652. Function DOS_GetDevOutputStatus(  Handle         : WORD;
  653.                               Var Status         : BYTE      ) : BYTE;
  654.  
  655. [PARAMETERS]
  656.  
  657. Handle      Device or File Handle
  658. Status      VAR Returned Device or File Output Status Code
  659.  
  660. [RETURNS]
  661.  
  662. (Function : Operation Error Code) (0=Success)
  663. (VAR      : [Status] Device or File Output Status Code)
  664.  
  665. [DESCRIPTION]
  666.  
  667. Status returns as follows:
  668.  
  669.    Devices:  $00 = Not Ready,  $FF = Ready
  670.    Files  :  $00 = Ready,      $FF = Ready
  671.  
  672. [SEE-ALSO]
  673.  
  674. [EXAMPLE]
  675.  
  676. -*)
  677.  
  678. Function DOS_GetDevOutputStatus(  Handle         : WORD;
  679.                               Var Status         : BYTE      ) : BYTE;
  680.  
  681.  
  682. {$IFNDEF OS2}
  683.  
  684. Assembler;
  685. ASM
  686.  
  687.   MOV  BX, Handle
  688.   MOV  AH, $44
  689.   MOV  AL, $07
  690.   INT  $21
  691.  
  692.   LES  DI, [Status]
  693.  
  694.   JNC  @@1
  695.  
  696.   MOV  AL, AH                { Code = Error }
  697.   MOV  byte PTR ES:DI, $00
  698.   JMP  @@2
  699.  
  700.  @@1:
  701.   MOV  byte PTR ES:DI, AL    { Status = Result }
  702.   XOR  AL, AL                { Code = No Error }
  703.  
  704.  @@2:
  705.  
  706. END;  { DOS_GetDevOutputStatus }
  707.  
  708. {$ELSE}
  709.  
  710. BEGIN
  711.  
  712.   {!^!}
  713.  
  714. END;
  715.  
  716. {$ENDIF}
  717.  
  718.  
  719. {────────────────────────────────────────────────────────────────────────────}
  720.  
  721. (*-
  722.  
  723. [FUNCTION]
  724.  
  725. Function DOS_IsRemovMediaDev(     Drive          : BYTE;
  726.                               Var Remov          : BOOLEAN   ) : WORD;
  727.  
  728. [PARAMETERS]
  729.  
  730. Drive       Selected Drive Number
  731. Remov       VAR Returned Is Media Removable? (TRUE=Yes)
  732.  
  733. [RETURNS]
  734.  
  735. (Function : Operation Error Code)
  736. (VAR      : [Remov] Is Media Removable?)
  737.  
  738. [DESCRIPTION]
  739.  
  740. Tests if Device is a Removable Media Device and returns the Results.
  741. TRUE=Removable Media Device, FALSE=Fixed Media Device
  742.  
  743. [SEE-ALSO]
  744.  
  745. [EXAMPLE]
  746.  
  747. -*)
  748.  
  749. {----------------------------------------------------------}
  750. {                  Function DOS_IsRemovMediaDev            }
  751. {----------------------------------------------------------}
  752. { IN : Drive (BYTE) Drive Number (+80h for HD)             }
  753. {  Var Remov (BOOLEAN) Returned Is Drive's Media Removable?}
  754. { OUT: (WORD) Error Code                                   }
  755. {----------------------------------------------------------}
  756.  
  757. Function DOS_IsRemovMediaDev(     Drive          : BYTE;
  758.                               Var Remov          : BOOLEAN   ) : WORD;
  759.  
  760. {$IFNDEF OS2}
  761.  
  762. Assembler;
  763. ASM
  764.  
  765.   MOV  BL, Drive
  766.   MOV  AH, $44
  767.   MOV  AL, $08
  768.   INT  $21
  769.  
  770.   LES  DI, [Remov]
  771.  
  772.   JNC @@1
  773.  
  774.   MOV  byte PTR ES:DI, $00   { Code = Error, Remov = Void }
  775.   Jmp  @@2
  776.  
  777.  @@1:
  778.   CMP  AL, 0
  779.   JNZ  @@1A
  780.  
  781.   MOV  byte PTR ES:DI, $01   { Remov = TRUE }
  782.   XOR  AX, AX                { Code = No Error }
  783.   JMP  @@2
  784.  
  785.  @@1A:
  786.   MOV  byte PTR ES:DI, $00   { Remov = FALSE }
  787.   XOR  AX, AX                { Code = No Error }
  788.  
  789.  @@2:
  790.  
  791. END;
  792.  
  793. {$ELSE}
  794.  
  795. BEGIN
  796.  
  797.  DOS_IsRemovMediaDev := $00; {!^!}
  798.  
  799. END;
  800.  
  801. {$ENDIF}
  802.  
  803. {────────────────────────────────────────────────────────────────────────────}
  804.  
  805. (*-
  806.  
  807. [FUNCTION]
  808.  
  809. Function DOS_GetMediaID(          Drive          : BYTE;
  810.                               Var InfoLevel      : WORD;
  811.                               Var SerialNbr      : LONGINT;
  812.                               Var VolLabel       : STRING;
  813.                               Var FileSysType    : STRING    ) : WORD;
  814.  
  815.  
  816. [PARAMETERS]
  817.  
  818. Drive       Drive Number
  819. InfoLevel   VAR Returned Information Access Level
  820. SerialNbr   VAR Returned Media Serial Number
  821. VolLabel    VAR Returned Media Volume Label
  822. FileSysType VAR Returned Media File System Type
  823.  
  824. [RETURNS]
  825.  
  826. (Function : Operation Error Code)
  827. (VAR      : [InfoLevel] Information Access Level)
  828. (VAR      : [SerialNbr] Media Serial Number)
  829. (VAR      : [VolLabel] Media Volume Label)
  830. (VAR      : [FileSysType] Media File System Type)
  831.  
  832. [DESCRIPTION]
  833.  
  834. [SEE-ALSO]
  835.  
  836. [EXAMPLE]
  837.  
  838. -*)
  839.  
  840. {----------------------------------------------------------}
  841. {                  Function DOS_GetMediaID                 }
  842. {----------------------------------------------------------}
  843. { IN :                                                     }
  844. { OUT:                                                     }
  845. {----------------------------------------------------------}
  846.  
  847. Function DOS_GetMediaID(          Drive          : BYTE;
  848.                               Var InfoLevel      : WORD;
  849.                               Var SerialNbr      : LONGINT;
  850.                               Var VolLabel       : STRING;
  851.                               Var FileSysType    : STRING    ) : WORD;
  852.  
  853.  
  854. {$IFNDEF OS2}
  855.  
  856. Type
  857.  
  858.   TMID = RECORD
  859.  
  860.     InfoLevel   : WORD;
  861.     SerialNbr   : LONGINT;
  862.     VolLabel    : ARRAY[1..11] of CHAR;
  863.     FileSysType : ARRAY[1..8] of BYTE;
  864.  
  865.   END;
  866.  
  867. Var
  868.   R   : REGISTERS;
  869.   MID : TMID;
  870.   Err : WORD;
  871.   i   : INTEGER;
  872.  
  873. BEGIN
  874. (*
  875.   ASM
  876.  
  877.     LDS  DX, MID
  878.     MOV  AH, $44
  879.     MOV  AL, $0D
  880.     MOV  CH, $08
  881.     MOV  CL, $66
  882.     INT  $21
  883.  
  884.     JNC @@1
  885.  
  886.     MOV  Err, AX             { Status = Error }
  887.     JMP  @@2
  888.  
  889.    @@1:
  890.     MOV  Err, 0              { Status = No Error }
  891.  
  892.    @@2:
  893.  
  894.   END;
  895. *)
  896.  
  897.   R.AH := $44;
  898.   R.AL := $0D;
  899.   R.BX := Drive;
  900.   R.CH := $08;
  901.   R.CL := $66;
  902.   R.DX := Ofs( MID );
  903.   R.DS := Seg( MID );
  904.   Intr( $21, R );
  905.  
  906.   If NOT Odd( R.Flags ) Then
  907.   BEGIN
  908.  
  909.     InfoLevel := MID.InfoLevel;
  910.     SerialNbr := MID.SerialNbr;
  911.  
  912.     Move ( MID.VolLabel, VolLabel[1], 11 );
  913.     VolLabel[0] := #11;
  914.     i := Pos( #0, VolLabel );
  915.     If ( i > 0 )  Then
  916.       VolLabel[0] := CHAR( i-1 );
  917.  
  918.     Move( MID.FileSysType, FileSysType[1], 8 );
  919.     FileSysType[0] := #8;
  920.  
  921.     DOS_GetMediaID := 0;
  922.  
  923.   END  { If Odd }
  924.  
  925.   Else
  926.   BEGIN
  927.  
  928.     InfoLevel   := 0;
  929.     SerialNbr   := 0;
  930.     VolLabel    := '';
  931.     FileSysType := '';
  932.  
  933.     DOS_GetMediaID := R.AX;
  934.  
  935.   END;  { If Odd / Else }
  936.  
  937. END;  { DOS_GetMediaID }
  938.  
  939. {$ELSE}
  940.  
  941. BEGIN
  942.  
  943.   DOS_GetMediaID := $FFFF;  {!^!}
  944.  
  945. END;
  946.  
  947. {$ENDIF}
  948.  
  949. {────────────────────────────────────────────────────────────────────────────}
  950.  
  951. (*-
  952.  
  953. [FUNCTION]
  954.  
  955. Function DOS_SetMediaID(          Drive          : BYTE;
  956.                                   InfoLevel      : WORD;
  957.                                   SerialNbr      : LONGINT;
  958.                                   VolLabel       : STRING;
  959.                                   FileSysType    : STRING    ) : WORD;
  960.  
  961. [PARAMETERS]
  962.  
  963. Drive       Drive Number
  964. InfoLevel   Information Access Level
  965. SerialNbr   Media Serial Number
  966. VolLabel    Media Volume Label
  967. FileSysType Media File System Type
  968.  
  969. [RETURNS]
  970.  
  971. Operation Error Code ($0000=Success)
  972.  
  973. [DESCRIPTION]
  974.  
  975. [SEE-ALSO]
  976.  
  977. [EXAMPLE]
  978.  
  979. -*)
  980.  
  981. Function DOS_SetMediaID(          Drive          : BYTE;
  982.                                   InfoLevel      : WORD;
  983.                                   SerialNbr      : LONGINT;
  984.                                   VolLabel       : STRING;
  985.                                   FileSysType    : STRING    ) : WORD;
  986.  
  987. {$IFNDEF OS2}
  988.  
  989. Type
  990.  
  991.   TMID = RECORD
  992.  
  993.     InfoLevel   : WORD;
  994.     SerialNbr   : LONGINT;
  995.     VolLabel    : ARRAY[1..11] of CHAR;
  996.     FileSysType : ARRAY[1..8] of BYTE;
  997.  
  998.   END;
  999.  
  1000. Var
  1001.  
  1002.   MID : TMID;
  1003.   Err : WORD;
  1004.   i   : INTEGER;
  1005.   R   : REGISTERS;
  1006.  
  1007. BEGIN
  1008.  
  1009.   MID.InfoLevel := InfoLevel;
  1010.   MID.SerialNbr := SerialNbr;
  1011.  
  1012.   Move( VolLabel[1], MID.VolLabel[1], 11 );
  1013.   If BYTE( VolLabel[0] ) < 11 Then
  1014.   BEGIN
  1015.  
  1016.     For i := BYTE( VolLabel[0] ) to 11 Do
  1017.       MID.VolLabel[ i ] := #0;
  1018.  
  1019.   END;
  1020.  
  1021.   Move( FileSysType[1], MID.FileSysType[1], 8 );
  1022.   If BYTE( FileSysType[0] ) < 8 Then
  1023.   BEGIN
  1024.  
  1025.     For i := BYTE( FileSysType[0] ) to 8 Do
  1026.       MID.FileSysType[ i ] := 0;
  1027.  
  1028.   END;
  1029.  
  1030.   R.AH := $44;
  1031.   R.AL := $0D;
  1032.   R.BX := Drive;
  1033.   R.CH := $08;
  1034.   R.CL := $46;
  1035.   R.DX := Ofs( MID );
  1036.   R.DS := Seg( MID );
  1037.  
  1038. (*
  1039.   ASM
  1040.  
  1041.     PUSH DS
  1042.  
  1043.     LDS  DX, MID
  1044.     MOV  AH, $44
  1045.     MOV  AL, $0D
  1046.     MOV  CH, $08
  1047.     MOV  CL, $46
  1048.     INT  $21
  1049.  
  1050.     JNC @@1
  1051.  
  1052.     MOV  Err, AX             { Status = Error }
  1053.     JMP  @@2
  1054.  
  1055.    @@1:
  1056.     MOV  Err, 0              { Status = No Error }
  1057.  
  1058.    @@2:
  1059.  
  1060.     POP  DS
  1061.  
  1062.   END;
  1063. *)
  1064.  
  1065.   If NOT Odd( R.Flags ) Then
  1066.     DOS_SetMediaID := 0
  1067.   Else
  1068.     DOS_SetMediaID := R.AX;
  1069.  
  1070. END;  { DOS_SetMediaID }
  1071.  
  1072.  
  1073. {$ELSE}
  1074.  
  1075. BEGIN
  1076.  
  1077.   DOS_SetMediaID := $FFFF; {!^!}
  1078.  
  1079. END;
  1080.  
  1081.  
  1082. {$ENDIF}
  1083. {────────────────────────────────────────────────────────────────────────────}
  1084.  
  1085. (*-
  1086.  
  1087. [FUNCTION]
  1088.  
  1089. Function DOS_GetExtErrText(   VAR Description    : STRING;
  1090.                               VAR ErrCause       : STRING;
  1091.                               VAR Recommend      : STRING;
  1092.                               VAR ErrSource      : STRING    ) : WORD;
  1093.  
  1094. [PARAMETERS]
  1095.  
  1096. Description VAR Returned Error Description Text
  1097. ErrCause    VAR Returned Error Cause Text
  1098. Recommend   VAR Returned Error Recommendation Text
  1099. ErrSource   VAR Returned Error Source Text
  1100.  
  1101. [RETURNS]
  1102.  
  1103. (Function : Operation Error Code, $0000=Success)
  1104. (VAR      : [Description] Error Description Text)
  1105. (VAR      : [ErrCause] Error Cause Text)
  1106. (VAR      : [Recommend] Error Recommendation Text)
  1107. (VAR      : [ErrSource] Error Source Text)
  1108.  
  1109. [DESCRIPTION]
  1110.  
  1111. Reads the Extended DOS Error Information for the last Error Condition
  1112. and returns the above information about it.
  1113.  
  1114. Based upon the Error Code, Returns each of the following:
  1115.   1) A Description of the Error Condition
  1116.   2) What may have Caused the Problem
  1117.   3) A Suggested Course of Action
  1118.   4) Device in which Error Occurred.
  1119.  
  1120. [SEE-ALSO]
  1121.  
  1122. [EXAMPLE]
  1123.  
  1124. -*)
  1125.  
  1126. Function DOS_GetExtErrText(   VAR Description    : STRING;
  1127.                               VAR ErrCause       : STRING;
  1128.                               VAR Recommend      : STRING;
  1129.                               VAR ErrSource      : STRING    ) : WORD;
  1130.  
  1131.  
  1132. {$IFNDEF OS2}
  1133.  
  1134. Var
  1135.  
  1136.   R : REGISTERS;
  1137.  
  1138. BEGIN
  1139.  
  1140.   { The following Registers are NOT preserved }
  1141.   { Used      = AX, BX, CH                    }
  1142.   { Destroyed = CL, DX, BP, SI, DI, DS, ES    }
  1143.  
  1144.   R.AH := $59;
  1145.   Intr( $21, R );
  1146.  
  1147.   Case R.AX Of
  1148.      0 : Description := 'No Error';
  1149.      1 : Description := 'Invalid Function Number';
  1150.      2 : Description := 'File Not Found';
  1151.      3 : Description := 'Path Not Found';
  1152.      4 : Description := 'Too Many Files Open';
  1153.      5 : Description := 'Access Denied';
  1154.      6 : Description := 'Invalid Handle';
  1155.      7 : Description := 'Memory Control Block Destroyed';
  1156.      8 : Description := 'Insufficient Memory';
  1157.      9 : Description := 'Invalid Memory Address';
  1158.     10 : Description := 'Invalid Environment';
  1159.     11 : Description := 'Invalid Format';
  1160.     12 : Description := 'Invalid Access Code';
  1161.     13 : Description := 'Invalid Data';
  1162.     14 : Description := 'Reserved';
  1163.     15 : Description := 'Invalid Drive';
  1164.     16 : Description := 'Current Directory Cannot be Removed';
  1165.     17 : Description := 'Different Device';
  1166.     18 : Description := 'No Additional Files';
  1167.     19 : Description := 'Medium Write Protected';
  1168.     20 : Description := 'Unknown Device';
  1169.     21 : Description := 'Device Not Ready';
  1170.     22 : Description := 'Unknown Command';
  1171.     23 : Description := 'CRC Error';
  1172.     24 : Description := 'Bad Request Structure Length';
  1173.     25 : Description := 'Seek Error';
  1174.     26 : Description := 'Unknown Medium Type';
  1175.     27 : Description := 'Sector Not Found';
  1176.     28 : Description := 'Printer Out of Paper';
  1177.     29 : Description := 'Write Error';
  1178.     30 : Description := 'Read Error';
  1179.     31 : Description := 'General Failure';
  1180.     32 : Description := 'Sharing Violation';
  1181.     33 : Description := 'Lock Violation';
  1182.     34 : Description := 'Unanthorized Disk Change';
  1183.     35 : Description := 'FCB Not Available';
  1184.     80 : Description := 'File Already Exists';
  1185.     81 : Description := 'Reserved';
  1186.     82 : Description := 'Directory Cannot be Created';
  1187.     83 : Description := 'Terminate After Call of Interrupt 24h';
  1188.   End;  { Case AX }
  1189.  
  1190.   Case R.BH Of
  1191.      1 : ErrCause := 'No Memory on the Medium';
  1192.      2 : ErrCause := 'Tempory Access Problem - May End Soon';
  1193.      3 : ErrCause := 'Access Unauthorized';
  1194.      4 : ErrCause := 'Internal Error in System Software';
  1195.      5 : ErrCause := 'Hardware Error';
  1196.     16 : ErrCause := 'Software Failure Not Caused by Running Application Program';
  1197.     17 : ErrCause := 'Application Program Error';
  1198.     18 : ErrCause := 'File Not Found';
  1199.     19 : ErrCause := 'Invalid File Format/Type';
  1200.     10 : ErrCause := 'File Locked';
  1201.     11 : ErrCause := 'Wrong Medium in Drive, Bad Disk or Medium Problem';
  1202.     12 : ErrCause := 'Other Error';
  1203.   End;  { Case BH }
  1204.  
  1205.   Case R.BL Of
  1206.      1 : Recommend := 'Repeat Process Several Times, Then Ask User to Abort/Ignore';
  1207.      2 : Recommend := 'Repeat Process Several Times Pausing Each Time, Then Ask User to Abort/Retry';
  1208.      3 : Recommend := 'Ask User for Correct Information (eg. Filename)';
  1209.      4 : Recommend := 'Terminate Program as Completely as Possible';
  1210.      5 : Recommend := 'Terminate Program NOW (No File Closing, etc)';
  1211.      6 : Recommend := 'Ignore Error';
  1212.      7 : Recommend := 'Ask User to Remove Error Source and Repeat Process';
  1213.   End;  { Case BL }
  1214.  
  1215.   Case R.CH Of
  1216.      1 : ErrSource := 'Unknown';
  1217.      2 : ErrSource := 'Block Device (Disk Drive, Hard Disk, etc)';
  1218.      3 : ErrSource := 'Network';
  1219.      4 : ErrSource := 'Serial Device';
  1220.      5 : ErrSource := 'RAM';
  1221.   End;  { Case CH }
  1222.  
  1223. END;  { DOS_GetExtErrText }
  1224.  
  1225. {$ELSE}
  1226.  
  1227. BEGIN
  1228.  
  1229.   Description := '<Info not available in OS/2>'; {!^!}
  1230.   ErrCause    := '';
  1231.   ErrSource   := '';
  1232.  
  1233. END;
  1234.  
  1235. {$ENDIF}
  1236.  
  1237.  
  1238. {-
  1239.  
  1240. [FUNCTION]
  1241.  
  1242. Function  GetDOSVersion                        : BYTE;
  1243.  
  1244. [PARAMETERS]
  1245.  
  1246. (None)
  1247.  
  1248. [RETURNS]
  1249.  
  1250. DOS version in BCD format
  1251.  
  1252. [DESCRIPTION]
  1253.  
  1254. Returns the Binary Coded Decimal format of the DOS Version
  1255.  
  1256. [SEE-ALSO]
  1257.  
  1258. [EXAMPLE]
  1259.  
  1260. -}
  1261.  
  1262.  
  1263.  
  1264. Function GetDOSVersion                         : WORD;
  1265.  
  1266. {$IFNDEF OS2}
  1267.  
  1268. Var
  1269.  
  1270.   R : REGISTERS;
  1271.  
  1272. BEGIN
  1273.  
  1274.   R.AH := $30;
  1275.   R.ES := $00;  { Load with 00 to avoid GPF in win/dpmi }
  1276.   R.DS := $00;
  1277.  
  1278.   Intr( $21, R );
  1279.   GetDosVersion := R.AL * 10 + R.AH;
  1280.  
  1281. END;
  1282.  
  1283. {$ELSE}
  1284.  
  1285. BEGIN
  1286.  
  1287.   GetDosVersion := 200; {!^!}
  1288.  
  1289. END;
  1290.  
  1291.  
  1292. {$ENDIF}
  1293.  
  1294. {────────────────────────────────────────────────────────────────────────────}
  1295.  
  1296. {-
  1297.  
  1298. [FUNCTION]
  1299.  
  1300. Function  DisketteStatus(            DriveA    : BOOLEAN ) : BYTE;
  1301.  
  1302. [PARAMETERS]
  1303.  
  1304. DriveA      Is test for Drive A: ? (A: = TRUE, B: = FALSE)
  1305.  
  1306. [RETURNS]
  1307.  
  1308. Floppy Drive Status code
  1309.  
  1310. [DESCRIPTION]
  1311.  
  1312. Tests the given Floppy Drive and returns the Status Code as follows:
  1313.      00h = diskette change signal not active (diskette not replaced)
  1314.      01h = invalid diskette parameter (disketted formatted?)
  1315.      06h = diskette change signal active (diskette replaced?)
  1316.      80h = diskette drive not ready (diskette in drive?)
  1317.  
  1318. [SEE-ALSO]
  1319.  
  1320. FloppyReady
  1321.  
  1322. [EXAMPLE]
  1323.  
  1324. -}
  1325.  
  1326.  
  1327. Function DisketteStatus(             Drive     : WORD   ) : BYTE;
  1328.  
  1329. {$IFNDEF OS2}
  1330.  
  1331. Var
  1332.  
  1333.   R : REGISTERS;
  1334.  
  1335. BEGIN
  1336.  
  1337.   R.AH := $16;
  1338.  
  1339.   R.DL := Drive;
  1340.  
  1341.   R.DS := 0;
  1342.   R.ES := 0;
  1343.  
  1344.   Intr( $13, R );
  1345.  
  1346.   DisketteStatus := R.AH;
  1347.  
  1348. END;
  1349.  
  1350. {$ELSE}
  1351.  
  1352. BEGIN
  1353.  
  1354.   DisketteStatus := $FF { !^! }
  1355.  
  1356. END;
  1357.  
  1358. {$ENDIF}
  1359.  
  1360. {────────────────────────────────────────────────────────────────────────────}
  1361.  
  1362. {-
  1363.  
  1364. [FUNCTION]
  1365.  
  1366. Function  FloppyReady(               DriveA    : BOOLEAN ) : BOOLEAN;
  1367.  
  1368. [PARAMETERS]
  1369.  
  1370. DriveA      Is test for Drive A: ? (A: = TRUE, B: = FALSE)
  1371.  
  1372. [RETURNS]
  1373.  
  1374. Whether the desired floppy drive was ready for use
  1375.  
  1376. [DESCRIPTION]
  1377.  
  1378. Test the given Floppy Drive to determine if the Drive was ready
  1379. for use (IE Drive accessable and Diskette is in the Drive) and
  1380. returns the results.
  1381.  
  1382. [SEE-ALSO]
  1383.  
  1384. DisketteStatus
  1385.  
  1386. [EXAMPLE]
  1387.  
  1388. -}
  1389.  
  1390.  
  1391. Function FloppyReady(                Drive     : WORD    ) : BOOLEAN;
  1392.  
  1393. Const
  1394.  
  1395.   cInvalidParam    = $01;
  1396.   cChgSignalActive = $06;
  1397.   cDriveNotReady   = $80;
  1398.  
  1399. Var
  1400.  
  1401.   Count  : INTEGER;
  1402.   Status : BYTE;
  1403.  
  1404. BEGIN
  1405.  
  1406.   Count := 0;
  1407.  
  1408.   Repeat
  1409.  
  1410.     Status := DisketteStatus( Drive );
  1411.     Inc( Count );
  1412.  
  1413.   Until (Status <> cChgSignalActive) or (Count >= 3);
  1414.  
  1415.   FloppyReady := (Status <> cDriveNotReady) AND
  1416.                  (Status <> cChgSignalActive);
  1417.  
  1418. END;
  1419.  
  1420. {────────────────────────────────────────────────────────────────────────────}
  1421.  
  1422. {-
  1423.  
  1424. [FUNCTION]
  1425.  
  1426. Function  PutSlash(                  S         : STRING  ) : STRING;
  1427.  
  1428. [PARAMETERS]
  1429.  
  1430. S           Source String to modify
  1431.  
  1432. [RETURNS]
  1433.  
  1434. [DESCRIPTION]
  1435.  
  1436. [SEE-ALSO]
  1437.  
  1438. UnPutSlash
  1439. PutDot
  1440. UnPutDot
  1441.  
  1442. [EXAMPLE]
  1443.  
  1444. -}
  1445.  
  1446. Function PutSlash(                     S         : STRING       ) : STRING;
  1447.  
  1448. BEGIN
  1449.  
  1450.   If ( S[0] = #0 ) OR
  1451.      ( S[Byte(S[0])] = ':' ) OR
  1452.      ( S[Byte(S[0])] = '\' ) Then
  1453.     PutSlash := S
  1454.   Else
  1455.     PutSlash := S + '\';
  1456.  
  1457. END;
  1458.  
  1459. {────────────────────────────────────────────────────────────────────────────}
  1460.  
  1461. {-
  1462.  
  1463. [FUNCTION]
  1464.  
  1465. Function  UnPutSlash(                S         : STRING  ) : STRING;
  1466.  
  1467. [PARAMETERS]
  1468.  
  1469. S           Source String to modify
  1470.  
  1471. [RETURNS]
  1472.  
  1473. [DESCRIPTION]
  1474.  
  1475. [SEE-ALSO]
  1476.  
  1477. PutSlash
  1478. PutDot
  1479. UnPutDot
  1480.  
  1481. [EXAMPLE]
  1482.  
  1483. -}
  1484.  
  1485. Function UnPutSlash(                   S         : STRING       ) : STRING;
  1486.  
  1487. BEGIN
  1488.  
  1489.   If (S[0] > #0) AND
  1490.      (S[Byte(S[0])] = '\') Then
  1491.     Delete(S, Byte(S[0]), 1);
  1492.  
  1493.   UnPutSlash := S;
  1494.  
  1495. END;
  1496.  
  1497. {────────────────────────────────────────────────────────────────────────────}
  1498.  
  1499. {-
  1500.  
  1501. [FUNCTION]
  1502.  
  1503. Function  PutDot(                    S         : STRING  ) : STRING;
  1504.  
  1505. [PARAMETERS]
  1506.  
  1507. S           Source String to modify
  1508.  
  1509. [RETURNS]
  1510.  
  1511. [DESCRIPTION]
  1512.  
  1513. [SEE-ALSO]
  1514.  
  1515. PutSlash
  1516. UnPutSlash
  1517. UnPutDot
  1518.  
  1519. [EXAMPLE]
  1520.  
  1521. -}
  1522.  
  1523. Function PutDot(                       S         : STRING       ) : STRING;
  1524.  
  1525. BEGIN
  1526.  
  1527.   If (Pos('.', S) = 0) Then
  1528.     PutDot := S + '.'
  1529.   Else
  1530.     PutDot := S;
  1531.  
  1532. END;
  1533.  
  1534. {────────────────────────────────────────────────────────────────────────────}
  1535.  
  1536. {-
  1537.  
  1538. [FUNCTION]
  1539.  
  1540. Function  UnPutDot(                  S         : STRING  ) : STRING;
  1541.  
  1542. [PARAMETERS]
  1543.  
  1544. S           Source String to modify
  1545.  
  1546. [RETURNS]
  1547.  
  1548. [DESCRIPTION]
  1549.  
  1550. [SEE-ALSO]
  1551.  
  1552. PutSlash
  1553. UnPutSlash
  1554. PutDot
  1555.  
  1556. [EXAMPLE]
  1557.  
  1558. -}
  1559.  
  1560. Function UnPutDot(                     S         : STRING       ) : STRING;
  1561.  
  1562. BEGIN
  1563.  
  1564.   If (S[0] > #0) AND
  1565.      (S[Byte(S[0])] = '.') Then
  1566.     Delete(S, Byte(S[0]), 1);
  1567.  
  1568.   UnPutDot := S;
  1569.  
  1570. END;
  1571.  
  1572. {────────────────────────────────────────────────────────────────────────────}
  1573.  
  1574. {-
  1575.  
  1576. [FUNCTION]
  1577.  
  1578. Function  FileExist(                 fn        : PathStr ) : BOOLEAN;
  1579.  
  1580. [PARAMETERS]
  1581.  
  1582. fn          ?
  1583.  
  1584. [RETURNS]
  1585.  
  1586. [DESCRIPTION]
  1587.  
  1588. [SEE-ALSO]
  1589.  
  1590. [EXAMPLE]
  1591.  
  1592. -}
  1593.  
  1594. Function FileExist(                    fn        : PathStr      ) : BOOLEAN;
  1595.  
  1596. Var
  1597.  
  1598.   reFirst : SearchRec;
  1599.  
  1600. BEGIN
  1601.  
  1602.   FillChar( reFirst, SizeOf(SearchRec), 0 );
  1603.   FindFirst( fn, ReadOnly OR Hidden OR SysFile OR Archive, reFirst );
  1604.   FileExist := (DosError = 0);
  1605.  
  1606. END;
  1607.  
  1608. {────────────────────────────────────────────────────────────────────────────}
  1609.  
  1610. {-
  1611.  
  1612. [FUNCTION]
  1613.  
  1614. Function  GetFileTime(               fn        : PathStr ) : LONGINT;
  1615.  
  1616. [PARAMETERS]
  1617.  
  1618. fn          ?
  1619.  
  1620. [RETURNS]
  1621.  
  1622. [DESCRIPTION]
  1623.  
  1624. [SEE-ALSO]
  1625.  
  1626. [EXAMPLE]
  1627.  
  1628. -}
  1629.  
  1630. Function GetFileTime(                  fn        : PathStr      ) : LONGINT;
  1631.  
  1632. Var
  1633.  
  1634.   reSearch : SearchRec;
  1635.  
  1636. BEGIN
  1637.  
  1638.   FillChar( reSearch, SizeOf(SearchRec), 0 );
  1639.   FindFirst( fn, AnyFile, reSearch );
  1640.  
  1641.   If (reSearch.Name <> '') Then
  1642.     GetFileTime := reSearch.Time
  1643.   Else
  1644.     GetFileTime := 0;
  1645.  
  1646. END;
  1647.  
  1648. {────────────────────────────────────────────────────────────────────────────}
  1649.  
  1650. {-
  1651.  
  1652. [FUNCTION]
  1653.  
  1654. Function  GetFileAttr(               fn        : PathStr ) : WORD;
  1655.  
  1656. [PARAMETERS]
  1657.  
  1658. fn          ?
  1659.  
  1660. [RETURNS]
  1661.  
  1662. [DESCRIPTION]
  1663.  
  1664. [SEE-ALSO]
  1665.  
  1666. [EXAMPLE]
  1667.  
  1668. -}
  1669.  
  1670. Function GetFileAttr(                  fn        : PathStr      ) : WORD;
  1671.  
  1672. Var
  1673.  
  1674.   F    : FILE;
  1675.   Attr : WORD;
  1676.  
  1677. BEGIN
  1678.  
  1679.   If FileExist( fn ) Then
  1680.   BEGIN
  1681.  
  1682.     Assign(F, fn);
  1683.     GetFAttr(F, Attr);
  1684.     GetFileAttr := Attr;
  1685.  
  1686.   END
  1687.   Else
  1688.     GetFileAttr := 0;
  1689.  
  1690. END;
  1691.  
  1692. {────────────────────────────────────────────────────────────────────────────}
  1693.  
  1694. {-
  1695.  
  1696. [FUNCTION]
  1697.  
  1698. Function  GetFileSize(               fn        : PathStr ) : LONGINT;
  1699.  
  1700. [PARAMETERS]
  1701.  
  1702. [RETURNS]
  1703.  
  1704. [DESCRIPTION]
  1705.  
  1706. [SEE-ALSO]
  1707.  
  1708. [EXAMPLE]
  1709.  
  1710. -}
  1711.  
  1712. Function GetFileSize(                  fn        : PathStr      ) : LONGINT;
  1713.  
  1714. Var
  1715.  
  1716.   reSearch : SearchRec;
  1717.  
  1718. BEGIN
  1719.  
  1720.   FillChar( reSearch, SizeOf(SearchRec), 0 );
  1721.   FindFirst( fn, AnyFile, reSearch );
  1722.  
  1723.   If (reSearch.Name <> '') Then
  1724.     GetFileSize := reSearch.Size
  1725.   Else
  1726.     GetFileSize := 0;
  1727.  
  1728. END;
  1729.  
  1730. {────────────────────────────────────────────────────────────────────────────}
  1731.  
  1732. {-
  1733.  
  1734. [FUNCTION]
  1735.  
  1736. Function  DirExist(                  stDir     : DirStr  ) : BOOLEAN;
  1737.  
  1738. [PARAMETERS]
  1739.  
  1740. stDir       Source Directory to Test Existance of
  1741.  
  1742. [RETURNS]
  1743.  
  1744. Whether or not the Indicated Directory Exists
  1745.  
  1746. [DESCRIPTION]
  1747.  
  1748. Tests the Indicated Source Directory to determine whether or not that
  1749. Sub-Directory Exists.  If so, returns TRUE, otherwise returns FALSE that
  1750. the Sub-Directory did not Exist.
  1751.  
  1752. [SEE-ALSO]
  1753.  
  1754. DirEmpty
  1755. PredDir
  1756. InDir
  1757. MkSubDir
  1758.  
  1759. [EXAMPLE]
  1760.  
  1761. -}
  1762.  
  1763. Function DirExist(                     stDir     : DirStr       ) : BOOLEAN;
  1764.  
  1765. Var
  1766.  
  1767.   DirAttr : WORD;
  1768.   fiTemp  : File;
  1769.  
  1770. BEGIN
  1771.  
  1772.   If Pos( '.', stDir ) = 0 Then
  1773.     Assign( fiTemp, stDir + '.' )
  1774.   Else
  1775.     Assign( fiTemp, stDir );
  1776.  
  1777.   GetFAttr( fiTemp, DirAttr );
  1778.  
  1779.   If ( DosError <> 0 ) Then
  1780.     DirExist := False
  1781.   Else
  1782.     DirExist := ( (DirAttr AND Directory) <> 0 );
  1783.  
  1784. END;
  1785.  
  1786. {────────────────────────────────────────────────────────────────────────────}
  1787.  
  1788. {-
  1789.  
  1790. [FUNCTION]
  1791.  
  1792. Function  DirEmpty(                  stDir     : DirStr  ) : BOOLEAN;
  1793.  
  1794. [PARAMETERS]
  1795.  
  1796. stDir       ?
  1797.  
  1798. [RETURNS]
  1799.  
  1800. Whether or not the Indicated Directory was Empty
  1801.  
  1802. [DESCRIPTION]
  1803.  
  1804. Tests the Sub-Directory indicated and determines if any files are contained
  1805. within it.  If so, returns FALSE else returns TRUE that Dir was Empty.
  1806.  
  1807. [SEE-ALSO]
  1808.  
  1809. DirExist
  1810. PredDir
  1811. InDir
  1812. MkSubDir
  1813.  
  1814. [EXAMPLE]
  1815.  
  1816. delete
  1817. -}
  1818.  
  1819. Function DirEmpty(                     stDir     : DirStr       ) : BOOLEAN;
  1820.  
  1821. Var
  1822.  
  1823.   reSearch : SearchRec;
  1824.   Count    : BYTE;
  1825.  
  1826. BEGIN
  1827.  
  1828.   stDir := PutSlash(stDir);
  1829.   Count := 0;
  1830.  
  1831.   FindFirst( stDir + '*.*', AnyFile, reSearch );
  1832.  
  1833.   While (Count < 2) AND
  1834.         (DosError <> 18) AND
  1835.         (reSearch.Attr AND Directory = Directory) Do
  1836.   BEGIN
  1837.  
  1838.     Inc(Count);
  1839.     FindNext( reSearch );
  1840.  
  1841.   END;
  1842.  
  1843.   DirEmpty := (Count = 2) AND (DosError = 18);
  1844.   DosError := 0;
  1845.  
  1846. END;
  1847.  
  1848.  
  1849. {────────────────────────────────────────────────────────────────────────────}
  1850.  
  1851. {-
  1852.  
  1853. [FUNCTION]
  1854.  
  1855. Function  EraseDir(                  stDir     : DirStr  ) : BOOLEAN;
  1856.  
  1857. [PARAMETERS]
  1858.  
  1859. stDir       SubDirectory to Empty
  1860.  
  1861. [RETURNS]
  1862.  
  1863. Whether or not the Indicated Directory was erased Successfully
  1864.  
  1865. [DESCRIPTION]
  1866.  
  1867. This function Deletes every File contained in the Source Sub-Directory
  1868. and returns whether or not the action was Successful.
  1869.  
  1870. [SEE-ALSO]
  1871.  
  1872. DirExist
  1873. PredDir
  1874. InDir
  1875. MkSubDir
  1876.  
  1877. [EXAMPLE]
  1878.  
  1879. delete
  1880. -}
  1881.  
  1882. Function  EraseDir(                  stDir     : DirStr  ) : BOOLEAN;
  1883.  
  1884. VAR
  1885.  
  1886.   SR  : SearchRec;
  1887.   F   : FILE;
  1888.  
  1889. BEGIN
  1890.  
  1891.   stDir := PutSlash( stDir );
  1892.  
  1893.   FindFirst( stDir+'*.*', AnyFile, SR );
  1894.  
  1895.   While DosError = 0 Do
  1896.   BEGIN
  1897.  
  1898.     Assign( F, SR.Name );
  1899.     Erase( F );
  1900.     FindNext( SR );
  1901.  
  1902.   END;  { While DosError }
  1903.  
  1904. END;  { EraseDir }
  1905.  
  1906. {───────────────────────────────────────────────────────────────────────────}
  1907.  
  1908. {-
  1909.  
  1910. [FUNCTION]
  1911.  
  1912. Function  PredDir(                   stDir     : DirStr  ) : DirStr;
  1913.  
  1914. [PARAMETERS]
  1915.  
  1916. stDir       ?
  1917.  
  1918. [RETURNS]
  1919.  
  1920. [DESCRIPTION]
  1921.  
  1922. [SEE-ALSO]
  1923.  
  1924. DirExist
  1925. DirEmpty
  1926. InDir
  1927. MkSubDir
  1928.  
  1929. [EXAMPLE]
  1930.  
  1931. -}
  1932.  
  1933. Function PredDir(                      stDir     : DirStr       ) : DirStr;
  1934.  
  1935. Var
  1936.  
  1937.   L1 : BYTE;
  1938.  
  1939. BEGIN
  1940.  
  1941.   stDir := PutSlash(stDir);
  1942.  
  1943.   L1 := Pred(Length(stDir));
  1944.   While (L1 > 2) AND (stDir[L1] <> '\') Do
  1945.     Dec(L1);
  1946.  
  1947.   If (L1 > 2) Then
  1948.     Delete( stDir, Succ(L1), Byte(stDir[0]) - L1 );
  1949.  
  1950.   PredDir := stDir;
  1951.  
  1952. END;
  1953.  
  1954. {───────────────────────────────────────────────────────────────────────────}
  1955.  
  1956. {-
  1957.  
  1958. [FUNCTION]
  1959.  
  1960. Function  InDir(                     stDir     : DirStr  ) : DirStr;
  1961.  
  1962. [PARAMETERS]
  1963.  
  1964. stDir       ?
  1965.  
  1966. [RETURNS]
  1967.  
  1968. [DESCRIPTION]
  1969.  
  1970. [SEE-ALSO]
  1971.  
  1972. DirExist
  1973. DirEmpty
  1974. PredDir
  1975. MkSubDir
  1976.  
  1977. [EXAMPLE]
  1978.  
  1979. -}
  1980.  
  1981. Function InDir(                        stDir     : DirStr       ) : DirStr;
  1982.  
  1983. Var
  1984.  
  1985.   L1 : INTEGER;
  1986.  
  1987. BEGIN
  1988.  
  1989.   stDir := PutSlash(stDir);
  1990.  
  1991.   L1 := Pred(Byte(stDir[0]));
  1992.   While (L1 > 2) AND (stDir[L1] <> '\') Do
  1993.     Dec(L1);
  1994.  
  1995.   If (L1 > 2) Then
  1996.     InDir := Copy( stDir, Succ(L1), Pred(Byte(stDir[0]) - L1) )
  1997.   Else
  1998.     InDir := stDir;
  1999.  
  2000. END;
  2001.  
  2002. {────────────────────────────────────────────────────────────────────────────}
  2003.  
  2004. {-
  2005.  
  2006. [FUNCTION]
  2007.  
  2008. Procedure MkSubDir(                  S         : STRING  );
  2009.  
  2010. [PARAMETERS]
  2011.  
  2012. S           Name of New SubDirectory (With or Without Trailing BackSlash)
  2013.  
  2014. [RETURNS]
  2015.  
  2016. (None)
  2017.  
  2018. [DESCRIPTION]
  2019.  
  2020. Takes care of handling the task of Creating a Sub-Directory with or
  2021. without the requirement of having to have a trailing BackSlash ("\")
  2022. in the New Directory Name.
  2023.  
  2024. [SEE-ALSO]
  2025.  
  2026. DirExist
  2027. DirEmpty
  2028. PredDir
  2029. InDir
  2030.  
  2031. [EXAMPLE]
  2032.  
  2033.   MkSubDir( 'C:\TEMP1' );
  2034.   MkSubDir( 'C:\TEMP2\' );
  2035.  
  2036.   (Both actions will create SubDirectories successfully - if disk space)
  2037. -}
  2038.  
  2039. Procedure MkSubDir(                    S         : STRING       );
  2040.  
  2041. Var
  2042.  
  2043.   Path  : STRING;
  2044.   IOErr : WORD;
  2045.  
  2046. BEGIN
  2047.  
  2048.   REPEAT
  2049.  
  2050.     {$I-}
  2051.     MkDir( S );
  2052.     IOErr := IOResult;
  2053.     {$I+}
  2054.  
  2055.     If (IOErr <> 0) Then
  2056.     BEGIN
  2057.  
  2058.       Path := UnPutSlash( PredDir( S ) );
  2059.       MkSubDir( Path );
  2060.  
  2061.     END;
  2062.  
  2063.   UNTIL (IOErr = 0);
  2064.  
  2065.   {error 3 = path not found}
  2066.  
  2067. END;
  2068.  
  2069. {────────────────────────────────────────────────────────────────────────────}
  2070.  
  2071. {-
  2072.  
  2073. [FUNCTION]
  2074.  
  2075. Function  MaskWildcards(             fn        : PathStr;
  2076.                                      fnMask    : PathStr ) : PathStr;
  2077.  
  2078. [PARAMETERS]
  2079.  
  2080. fn          ?
  2081. fnMask      ?
  2082.  
  2083. [RETURNS]
  2084.  
  2085. [DESCRIPTION]
  2086.  
  2087. [SEE-ALSO]
  2088.  
  2089. [EXAMPLE]
  2090.  
  2091. -}
  2092.  
  2093. Function MaskWildcards(                fn        : PathStr;
  2094.                                        fnMask    : PathStr      ) : PathStr;
  2095.  
  2096. Var
  2097.  
  2098.   poFn    : BYTE;
  2099.   poMask  : BYTE;
  2100.   poFnDot : BYTE;
  2101.   seDir   : DirStr;
  2102.   neFn    : PathStr;
  2103.  
  2104. BEGIN
  2105.  
  2106.   {---------------------}
  2107.   { Setup fn and fnMask }
  2108.   {---------------------}
  2109.  
  2110.   If (fnMask = '') Then
  2111.   BEGIN
  2112.  
  2113.     MaskWildcards := fn;
  2114.     Exit;
  2115.  
  2116.   END;
  2117.  
  2118.   {--------------------------------}
  2119.   { Get starting point of filename }
  2120.   {--------------------------------}
  2121.  
  2122.   seDir := PredDir( fn );
  2123.  
  2124.   poFn := Pos(seDir, fn);
  2125.   If poFn <> 0 Then
  2126.     Inc( poFn, Length(seDir) )
  2127.   Else
  2128.   BEGIN
  2129.  
  2130.     seDir := '';
  2131.     poFn  := 1;
  2132.  
  2133.   END;
  2134.  
  2135.   {----------------------------------}
  2136.   { Find location of dot in filename }
  2137.   {----------------------------------}
  2138.  
  2139.   poFnDot := poFn;
  2140.   While (fn[poFnDot] <> '.') AND
  2141.         (poFnDot < Length(fn)) Do
  2142.     Inc(poFnDot);
  2143.   If fn[poFnDot] <> '.' Then
  2144.     poFnDot := 0;
  2145.  
  2146.   poMask := Pos('.', fnMask);
  2147.   If poMask = 0 Then
  2148.     fnMask := fnMask + '.';
  2149.  
  2150.   {------------}
  2151.   { Begin mask }
  2152.   {------------}
  2153.  
  2154.   poMask := 1;
  2155.   neFn := '';
  2156.  
  2157.   While (poMask <= Length(fnMask)) Do
  2158.   BEGIN
  2159.  
  2160.     If (fnMask[poMask] <> '?') AND
  2161.        (fnMask[poMask] <> '*') AND
  2162.        (fnMask[poMask] <> '.') Then
  2163.  
  2164.     BEGIN
  2165.  
  2166.       neFn := neFn + fnMask[poMask];
  2167.       Inc(poMask);
  2168.  
  2169.       If (fn[poFn] <> '.') Then
  2170.         Inc(poFn);
  2171.  
  2172.     END
  2173.     Else
  2174.     BEGIN
  2175.  
  2176.       Case fnMask[poMask] of
  2177.  
  2178.         '.' :
  2179.  
  2180.           BEGIN
  2181.  
  2182.             Inc(poMask);
  2183.  
  2184.             While (fn[Pred(poFn)] <> '.') AND
  2185.                   (poFn <= Length(Fn)) Do
  2186.               Inc(poFn);
  2187.  
  2188.             neFn := neFn + '.';
  2189.  
  2190.           END;
  2191.  
  2192.        {-----}
  2193.  
  2194.        '?' :
  2195.  
  2196.          BEGIN
  2197.  
  2198.            If fn[poFn] <> '.' Then
  2199.            BEGIN
  2200.  
  2201.              neFn := neFn + fn[poFn];
  2202.  
  2203.              Inc(poFn);
  2204.  
  2205.            END;
  2206.  
  2207.            Inc(poMask);
  2208.  
  2209.          END;
  2210.  
  2211.        {-----}
  2212.  
  2213.        '*' :  { any zero or more characters in this position }
  2214.  
  2215.          BEGIN
  2216.  
  2217.            While (fnMask[poMask] <> '.') AND
  2218.                  (poMask <= Length(fnMask)) Do
  2219.              Inc(poMask);
  2220.  
  2221.            While (fn[poFn] <> '.') AND
  2222.                  (poFn <= Length(Fn)) Do
  2223.            BEGIN
  2224.  
  2225.              neFn := neFn + fn[poFn];
  2226.              Inc(poFn);
  2227.  
  2228.            END;
  2229.  
  2230.          END;
  2231.  
  2232.        {-----}
  2233.  
  2234.       End;
  2235.  
  2236.     END;
  2237.  
  2238.   END;
  2239.  
  2240.   MaskWildcards := seDir + neFn;
  2241.  
  2242. END;
  2243.  
  2244. {────────────────────────────────────────────────────────────────────────────}
  2245.  
  2246. {-
  2247.  
  2248. [FUNCTION]
  2249.  
  2250. Procedure FileCRC16(                 FName     : STRING;
  2251.                                  Var Result    : WORD );
  2252.  
  2253. [PARAMETERS]
  2254.  
  2255. FName       Name of Source File to CRC
  2256. Result      VAR Modified 16-Bit CRC Checksum of Source File
  2257.  
  2258. [RETURNS]
  2259.  
  2260. (Function : None)
  2261. (Var      : (Result) Modified 16-Bit CRC Checksum of Source File)
  2262.  
  2263. [DESCRIPTION]
  2264.  
  2265. WARNING: File MUST Exist as there is NO Error Checking on this.
  2266.  
  2267. [SEE-ALSO]
  2268.  
  2269. FileCRC32
  2270.  
  2271. [EXAMPLE]
  2272.  
  2273. -}
  2274.  
  2275. Procedure FileCRC16(                 FName     : STRING;
  2276.                                  Var Result    : WORD );
  2277.  
  2278. Type
  2279.  
  2280.   TBuffer = Array[0..0] of BYTE;
  2281.   PBuffer = ^TBuffer;
  2282.  
  2283. Var
  2284.  
  2285.   fiBuf      : FILE;
  2286.   Buf        : PBuffer;
  2287.   Count      : WORD;
  2288.   L1         : WORD;
  2289.   NumRead    : WORD;
  2290.  
  2291. BEGIN
  2292.  
  2293.   If NOT FileExist(FName) Then
  2294.     Exit;
  2295.  
  2296.   Assign( fiBuf, FName );
  2297.   Reset( fiBuf, 1 );
  2298.  
  2299.   Count := $FFF8;
  2300.   If (MaxAvail < Count) Then
  2301.     Count := MaxAvail;
  2302.  
  2303.   GetMem( Buf, Count );
  2304.  
  2305.   Result := $FFFF;
  2306.  
  2307.   REPEAT
  2308.  
  2309.     BlockRead( fiBuf, Buf^, Count, NumRead );
  2310.  
  2311.     For L1 := 1 to NumRead Do
  2312.       CRC16Char( Char(Buf^[L1]), Result );
  2313.  
  2314.   UNTIL (NumRead = 0);
  2315.  
  2316.   FreeMem( Buf, Count );
  2317.  
  2318.   Close( fiBuf );
  2319.  
  2320. END;
  2321.  
  2322. {────────────────────────────────────────────────────────────────────────────}
  2323.  
  2324. {-
  2325.  
  2326. [FUNCTION]
  2327.  
  2328. Procedure FileCRC32(                 FName     : STRING;
  2329.                                  Var Result    : LONGINT );
  2330.  
  2331. [PARAMETERS]
  2332.  
  2333. FName       Name of Source File to CRC
  2334. Result      VAR 32-Bit CRC Checksum of Source File
  2335.  
  2336. [RETURNS]
  2337.  
  2338. (Function : None)
  2339. (Var      : (Result) 32-Bit CRC Checksum of Source File)
  2340.  
  2341. [DESCRIPTION]
  2342.  
  2343. WARNING: File MUST Exist as there is NO Error Checking on this.
  2344.  
  2345. [SEE-ALSO]
  2346.  
  2347. FileCRC16
  2348.  
  2349. [EXAMPLE]
  2350.  
  2351. -}
  2352.  
  2353. Procedure FileCRC32(                 FName     : STRING;
  2354.                                  Var Result    : LONGINT );
  2355.  
  2356. Type
  2357.  
  2358.   TBuffer = Array[0..0] of BYTE;
  2359.   PBuffer = ^TBuffer;
  2360.  
  2361. Var
  2362.  
  2363.   fiBuf      : FILE;
  2364.   Buf        : PBuffer;
  2365.   Count      : WORD;
  2366.   L1         : WORD;
  2367.   NumRead    : WORD;
  2368.  
  2369. BEGIN
  2370.  
  2371.   If NOT FileExist(FName) Then
  2372.     Exit;
  2373.  
  2374.   Assign( fiBuf, FName );
  2375.   Reset( fiBuf, 1 );
  2376.  
  2377.   Count := $FFF8;
  2378.   If (MaxAvail < Count) Then
  2379.     Count := MaxAvail;
  2380.  
  2381.   GetMem( Buf, Count );
  2382.  
  2383.   Result := $FFFFFFFF;
  2384.  
  2385.   REPEAT
  2386.  
  2387.     BlockRead( fiBuf, Buf^, Count, NumRead );
  2388.  
  2389.     For L1 := 1 to NumRead Do
  2390.       CRC32Char( Char(Buf^[L1]), Result );
  2391.  
  2392.   UNTIL (NumRead = 0);
  2393.  
  2394.   FreeMem( Buf, Count );
  2395.  
  2396.   Close( fiBuf );
  2397.  
  2398. END;
  2399.  
  2400. {────────────────────────────────────────────────────────────────────────────}
  2401.  
  2402. (*-
  2403.  
  2404. [FUNCTION]
  2405.  
  2406. Function  GetVolLabel(            Drive          : BYTE      ) : STRING;
  2407.  
  2408. [PARAMETERS]
  2409.  
  2410. Drive       Source Drive Number (0=Default)
  2411.  
  2412. [RETURNS]
  2413.  
  2414. The Volume Label of the Selected Drive
  2415.  
  2416. [DESCRIPTION]
  2417.  
  2418. Retrieves the Volume Label String from the selected Drive.
  2419. If there was an Error the String comes back empty.
  2420.  
  2421. [SEE-ALSO]
  2422.  
  2423. GetFileSysType
  2424. DOS_GetMediaID { VDOS }
  2425. DOS_SetMediaID { VDOS }
  2426.  
  2427. [EXAMPLE]
  2428.  
  2429. VAR
  2430.   S : STRING;
  2431.  
  2432. BEGIN
  2433.  
  2434.   S := GetVolLabel( 0 );
  2435.  
  2436.   { S comes back as whatever the current drive Volume Label is }
  2437.  
  2438. END;
  2439.  
  2440. -*)
  2441.  
  2442. Function  GetVolLabel(            Drive          : BYTE      ) : STRING;
  2443.  
  2444. VAR
  2445.   Info  : WORD;
  2446.   Ser   : LONGINT;
  2447.   Vol,
  2448.   Ftype : STRING;
  2449.  
  2450. BEGIN
  2451.  
  2452.   If DOS_GetMediaID( Drive, Info, Ser, Vol, FType ) = $00 Then
  2453.     GetVolLabel := Vol
  2454.   Else
  2455.     GetVolLabel := '';
  2456.  
  2457. END;  {  GetVolLabel }
  2458.  
  2459. {────────────────────────────────────────────────────────────────────────────}
  2460.  
  2461. (*-
  2462.  
  2463. [FUNCTION]
  2464.  
  2465. Function  GetFileSysType(         Drive          : BYTE      ) : STRING;
  2466.  
  2467. [PARAMETERS]
  2468.  
  2469. Drive       Source Drive Number (0=Default)
  2470.  
  2471. [RETURNS]
  2472.  
  2473. File System Type Text of the selected Drive
  2474.  
  2475. [DESCRIPTION]
  2476.  
  2477. Retrieves the File System Type String from the selected Drive.
  2478. If there was an Error the String comes back empty.
  2479.  
  2480. [SEE-ALSO]
  2481.  
  2482. GetVolLabel
  2483. DOS_GetMediaID { VDOS }
  2484. DOS_SetMediaID { VDOS }
  2485.  
  2486. [EXAMPLE]
  2487.  
  2488. VAR
  2489.   S : STRING;
  2490.  
  2491. BEGIN
  2492.  
  2493.   S := GetFileSysType( 0 );
  2494.  
  2495.   { S = 'FAT16' - for this example }
  2496.  
  2497. END;
  2498.  
  2499. -*)
  2500.  
  2501. Function  GetFileSysType(         Drive          : BYTE      ) : STRING;
  2502.  
  2503. VAR
  2504.   Info  : WORD;
  2505.   Ser   : LONGINT;
  2506.   Vol,
  2507.   Ftype : STRING;
  2508.  
  2509. BEGIN
  2510.  
  2511.   If DOS_GetMediaID( Drive, Info, Ser, Vol, FType ) = $00 Then
  2512.     GetFileSysType := FType
  2513.   Else
  2514.     GetFileSysType := '';
  2515.  
  2516. END;  { GetFileSysType }
  2517. {────────────────────────────────────────────────────────────────────────────}
  2518.  
  2519. (*-
  2520.  
  2521. [FUNCTION]
  2522.  
  2523. Function  DriveExist(                Drive     : CHAR    ) : BOOLEAN;
  2524.  
  2525. [PARAMETERS]
  2526.  
  2527. Drive       Drive letter to test existance of
  2528.  
  2529. [RETURNS]
  2530.  
  2531. Whether or not the indicated drive exists
  2532.  
  2533. [DESCRIPTION]
  2534.  
  2535. Tests the indicated drives to determine whether or not that it exists or
  2536. ready.
  2537.  
  2538. [SEE-ALSO]
  2539.  
  2540. [EXAMPLE]
  2541.  
  2542. -*)
  2543.  
  2544. Function  DriveExist(                Drive     : CHAR    ) : BOOLEAN;
  2545. BEGIN
  2546.  
  2547.   DriveExist := DiskSize( Byte(UpCase(Drive)) - 64 ) <> -1;
  2548.  
  2549. END;
  2550.  
  2551. {────────────────────────────────────────────────────────────────────────────}
  2552.  
  2553. (*-
  2554.  
  2555. [FUNCTION]
  2556.  
  2557. Function  DeviceExist(                Name      : STRING  ) : BOOLEAN;
  2558.  
  2559. [PARAMETERS]
  2560.  
  2561. Name        Name of device to check
  2562.  
  2563. [RETURNS]
  2564.  
  2565. Whether or not the indicated device exists
  2566.  
  2567. [DESCRIPTION]
  2568.  
  2569. Tests the indicated device to determine whether or not it exist or is a
  2570. device.
  2571.  
  2572. [SEE-ALSO]
  2573.  
  2574. [EXAMPLE]
  2575.  
  2576. -*)
  2577.  
  2578. Function  DeviceExist(                Name      : STRING  ) : BOOLEAN;
  2579.  
  2580. {$IFNDEF OS2}
  2581.  
  2582. Var
  2583.  
  2584.   F : File;
  2585.   N : Integer Absolute F;
  2586.   R : Registers;
  2587.  
  2588. BEGIN
  2589.  
  2590.   DeviceExist := False;
  2591.   Assign( F, Name );
  2592.   Reset( F );
  2593.  
  2594.   If IOResult <> 0 Then
  2595.     Exit;
  2596.  
  2597.   R.AX := $4400;
  2598.   R.BX := N;
  2599.   R.ES := $00;  { Load with 00 to avoid GPF in win/dpmi }
  2600.   R.DS := $00;
  2601.  
  2602.   Intr( $21, R );
  2603.  
  2604.   DeviceExist := (R.DX and $80) <> 0;  { check if 8th bit is set (device) }
  2605.   Close( F );
  2606.  
  2607. END;
  2608.  
  2609. {$ELSE}
  2610.  
  2611. BEGIN
  2612.  
  2613.   DeviceExist := FALSE;
  2614.  
  2615. END;
  2616.  
  2617. {$ENDIF}
  2618.  
  2619. {────────────────────────────────────────────────────────────────────────── }
  2620.  
  2621. (*
  2622.  
  2623. Function TextSeek(                Var F         : TEXT;
  2624.                                       NewPos    : LONGINT ) : WORD;
  2625.  
  2626.  
  2627. Var
  2628.  
  2629.   Err    : WORD;
  2630.   CurPos : LONGINT;
  2631.  
  2632. BEGIN
  2633.  
  2634.   If TextRec(F).Mode=fmInput Then
  2635.   BEGIN
  2636.  
  2637.     ASM
  2638.  
  2639.       MOV Err, 0
  2640.  
  2641.       MOV AX, $4201
  2642.       MOV BX, TextRec(F).Handle
  2643.       MOV CX, 0
  2644.       MOV DX, 0
  2645.       INT 21h
  2646.  
  2647.       JNC @@OK
  2648.         2
  2649.       MOV Err, AX
  2650.  
  2651.       JMP @@out
  2652.  
  2653.      @@ok:
  2654.  
  2655.       MOV word PTR [CurPos  ], AX
  2656.       MOV word PTR [CurPos+2], DX
  2657.  
  2658.      @@out:
  2659.  
  2660.     END;
  2661.  
  2662.     Dec( CurPos, TextRec(F).BufEnd );
  2663.  
  2664.     CurPos := NewPos-CurPos;
  2665.  
  2666.     If CurPos>=0 and (CurPos<TextRef(F).BufEnd) Then
  2667.       TextRec(F).BufEnd := CurPos
  2668.     ELSE
  2669.     BEGIN
  2670.  
  2671.       ASM
  2672.  
  2673.         MOV AX, $4200
  2674.         MOV BX, TextRec(F).Handle
  2675.         MOV CX, word PTR [CurPos+2]
  2676.         MOV DX, word PTR [CurPos  ]
  2677.         INT 21h
  2678.  
  2679.         JNC @@out2
  2680.  
  2681.  
  2682.  
  2683.         @@out2:
  2684.  
  2685.       END;
  2686.  
  2687.       TextRec( F ).BufEnd := 0;
  2688.       TextRef( F ).BufPos := 0;
  2689.  
  2690.     END;
  2691.  
  2692.   END
  2693.   ELSE
  2694.     TextSeek := $FFFF;
  2695.  
  2696. END;
  2697.  
  2698. *)
  2699.  
  2700.  
  2701.  
  2702.  
  2703. Function  GetDirFromPath(            Path      : STRING  ) : STRING;
  2704.  
  2705. Var
  2706.  
  2707.   Dir  : DirStr;
  2708.   Name : NameStr;
  2709.   Ext  : ExtStr;
  2710.  
  2711. BEGIN
  2712.  
  2713.   FSplit( Path, Dir, Name, Ext );
  2714.  
  2715.   GetDirFromPath := Dir;
  2716.  
  2717. END;
  2718.  
  2719. Function  GetNameFromPath(           Path      : STRING  ) : STRING;
  2720.  
  2721. Var
  2722.  
  2723.   Dir  : DirStr;
  2724.   Name : NameStr;
  2725.   Ext  : ExtStr;
  2726.  
  2727. BEGIN
  2728.  
  2729.   FSplit( Path, Dir, Name, Ext );
  2730.  
  2731.   GetNameFromPath := Name;
  2732.  
  2733. END;
  2734.  
  2735.  
  2736. Function  GetExtFromPath(            Path      : STRING  ) : STRING;
  2737.  
  2738. Var
  2739.  
  2740.   Dir  : DirStr;
  2741.   Name : NameStr;
  2742.   Ext  : ExtStr;
  2743.  
  2744. BEGIN
  2745.  
  2746.   FSplit( Path, Dir, Name, Ext );
  2747.  
  2748.   GetExtFromPath := Ext;
  2749.  
  2750. END;
  2751.  
  2752.  
  2753. Function  RemoveExtraSlash(          Path      : STRING  ) : STRING;
  2754.  
  2755. BEGIN
  2756.  
  2757.   If ( Path[ Length(Path) ] = '\'    ) and
  2758.      ( length(Path) > 1              ) and
  2759.      ( Path[ length(Path)-1 ] <> ':' ) Then
  2760.  
  2761.      Delete( Path, Length(Path), 1 );
  2762.  
  2763.   RemoveExtraSlash := Path;
  2764.  
  2765. END;
  2766.  
  2767.  
  2768. {────────────────────────────────────────────────────────────────────────────}
  2769. {────────────────────────────────────────────────────────────────────────────}
  2770.  
  2771. BEGIN
  2772. END.
  2773.